package com.demo.service.serviceImpl;

import com.demo.common.Pager;
import com.demo.common.StringUtil;
import com.demo.dao.SysDicDao;
import com.demo.model.SysDic;
import com.demo.model.TabUsers;
import com.demo.service.SysDicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class SysDicServiceImpl implements SysDicService {


    @Resource
    private SysDicDao dao;

    @Override
    public void findAll(SysDic d, HttpServletRequest request) {
        String url="sys_dic_view?dickeys="+d.getDickeys();
        int size=20;
        if(StringUtil.isNotEmpty(d.getDickeys()))
            d.setDickeys("%"+d.getDickeys()+"%");
        int rows=dao.countByExampleSearch(d);
        int cpage= request.getParameter("pager") == null ? 1 : Integer
                .parseInt(request.getParameter("pager"));
        if(cpage==0) {
            cpage=1;
        }
        String pager= Pager.getPagerStr(url, size, rows, cpage, 1);
        request.setAttribute("pager", pager);
        SysDic query=new SysDic(d.getDickeys(),size*(cpage-1),size,"id","desc");
        List<SysDic> list=dao.searchByPage(query);
        request.setAttribute("rows",rows);
        request.setAttribute("list", list);
    }

    @Override
    public void update_dic_flag(SysDic d) {
        dao.update_dic_flag(d);
    }

    @Override
    public SysDic findById(String id) {
        return dao.findById(id);
    }

    @Override
    public boolean update(SysDic d) {
        return dao.update(d);
    }

    @Override
    public boolean save(SysDic d) {
        return dao.save(d);
    }

    @Override
    public void del(String id) {
        dao.del(id);
    }

    @Override
    public List<SysDic> selectAll() {
        return dao.selectAll();
    }

    @Override
    public SysDic findBykeys(String key) {
        return dao.findBykeys(key);
    }
}
